package com.suep.business.mapper;

import com.suep.business.domain.OrderItem;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;

import java.math.BigDecimal;
import java.util.List;

@Mapper
public interface OrderItemMapper {

    // 主键精确查询
    @Select("SELECT * FROM order_item WHERE order_item_id = #{id}")
    OrderItem selectOrderItemById(@Param("id") Integer id);

    // 外键（OrderId）查询
    @Select("SELECT * FROM order_item WHERE order_id = #{orderId}")
    List<OrderItem> selectOrderItemByOrderId(@Param("orderId") Long orderId);

    // 外键（mealId）查询
    @Select("SELECT * FROM order_item WHERE meal_id = #{mealId}")
    List<OrderItem> selectOrderItemByMealId(@Param("mealId") Integer mealId);

    // 主键精确删除
    @Delete("DELETE FROM order_item WHERE order_item_id = #{id}")
    Integer deleteOrderItemById(@Param("id") Integer id);

    // 插入
    @Insert("INSERT INTO order_item (order_item_id, order_id, meal_id, meal_name, quantity, price) VALUES (#{orderItemId}, #{orderId}, #{mealId}, #{mealName}, #{quantity}, #{price})")
    Integer insertOrderItem(OrderItem orderItem);

    // 更新（假设更新所有字段，可根据实际需求调整）
    @Update("UPDATE order_item SET order_id = #{orderId}, meal_id = #{mealId}, meal_name = #{mealName}, quantity = #{quantity}, price = #{price} WHERE order_item_Id = #{orderItemId}")
    Integer updateOrderItemById(OrderItem orderItem);
}